package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppRoomAdmin;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * 房间排麦
 *
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppRoomPaimaiDao.java
 * @Description TODO
 * @createTime 2021年07月29日 14:44:00
 */
@Repository
public class AppRoomAdminDao extends BaseDao<AppRoomAdmin> {

    /**
     * 详情
     *
     * @Param: [id]
     * @return: com.vf.admin.miaodong.entity.AppRoomPaimai
     * @Author: zhouyunyi
     * @Date: 2021/07/29
     * @Time: 14:47
     */
    public AppRoomAdmin get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_admin  where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoomAdmin.class);
    }

    /**
     * 修改，保存
     *
     * @Param: [haoYou]
     * @return: void
     * @Author: zhouyunyi
     * @Date: 2021/07/29
     * @Time: 14:47
     */
    public void save(AppRoomAdmin haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     *
     * @Param: [id]
     * @return: void
     * @Author: zhouyunyi
     * @Date: 2021/07/29
     * @Time: 14:48
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = " delete  from app_room_admin  where id = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 根据房间id，用户id查询
     *
     * @Param: [roomid, userid]
     * @return: com.vf.admin.miaodong.entity.AppRoomPaimai
     * @Author: zhouyunyi
     * @Date: 2021/07/29
     * @Time: 14:50
     */
    public AppRoomAdmin getRoom(Integer roomid, Integer adminuserid) {
        if (StringEx.isNullOrLing(roomid)) {
            return null;
        }
        if (StringEx.isNull(adminuserid)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_room_admin  where 1=1");
        sbStr.append(" and roomid = ? ");
        paramList.add(roomid);
        sbStr.append(" and adminuserid = ? ");
        paramList.add(adminuserid);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRoomAdmin.class);
    }


    /**
     * 房间排麦列表
     *
     * @Param: [map, splitPageBean]
     * @return: java.util.List<com.vf.admin.miaodong.entity.AppRoomPaimai>
     * @Author: zhouyunyi
     * @Date: 2021/07/29
     * @Time: 15:23
     */
    public List<AppRoomAdmin> adminList(Integer roomid, SplitPageBean splitPageBean) {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT * FROM app_room_admin  WHERE 1=1 ");
        sbStr.append(" and roomid = ? ");
        paramList.add(roomid);

        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppRoomAdmin.class, splitPageBean);
    }

    /**
     * 更新用户昵称
     *
     * @Param: [userid 用户id, nick 用户昵称]
     * @return: void
     * @Author: zhouyunyi
     * @Date: 2021/07/29
     * @Time: 16:41
     */
    public void updateNick(Integer userid, String nick) {
        if (StringEx.isNull(userid)) {
            return;
        }
        if (StringEx.isNull(nick)) {
            return;
        }
        String sql = " UPDATE app_room_admin SET nick = ? WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(nick);
        paramList.add(userid);
        this.update(sql, paramList);
    }

    /**
     * 更新用户头像
     *
     * @Param: [userid 用户id, pic 用户头像]
     * @return: void
     * @Author: zhouyunyi
     * @Date: 2021/07/29
     * @Time: 16:44
     */
    public void updatePic(Integer userid, String pic) {
        if (StringEx.isNull(userid)) {
            return;
        }
        if (StringEx.isNull(pic)) {
            return;
        }
        String sql = " UPDATE app_room_admin SET pic = ? WHERE userid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(pic);
        paramList.add(userid);
        this.update(sql, paramList);
    }

    /**
     * 更新管理员昵称
     *
     * @Param: [userid 用户id, nick 用户昵称]
     * @return: void
     * @Author: zhouyunyi
     * @Date: 2021/07/29
     * @Time: 16:41
     */
    public void updateAdminNick(Integer userid, String nick) {
        if (StringEx.isNull(userid)) {
            return;
        }
        if (StringEx.isNull(nick)) {
            return;
        }
        String sql = " UPDATE app_room_admin SET adminnick = ? WHERE adminuserid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(nick);
        paramList.add(userid);
        this.update(sql, paramList);
    }

    /**
     * 更新管理员头像
     *
     * @Param: [userid 用户id, pic 用户头像]
     * @return: void
     * @Author: zhouyunyi
     * @Date: 2021/07/29
     * @Time: 16:44
     */
    public void updateAdminPic(Integer userid, String pic) {
        if (StringEx.isNull(userid)) {
            return;
        }
        if (StringEx.isNull(pic)) {
            return;
        }
        String sql = " UPDATE app_room_admin SET adminpic = ? WHERE adminuserid = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(pic);
        paramList.add(userid);
        this.update(sql, paramList);
    }


}
